package 图.岛屿问题;

import java.util.ArrayList;
import java.util.concurrent.TimeUnit;

/**
 * @author aodre , QQ : 480029069
 * @date 2023/9/10 15:29
 */
public class lc100030将石头分散到网格图的最少移动次数 {




    public int recursion(int i,int j,int count){
        return 0;
    }


    /*
     Arignote 的做法
     */
    public int minimumMoves(int[][] grid) {
        ArrayList<int[]> list1 = new ArrayList<>(), list2 = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (grid[i][j] == 0) {
                    list1.add(new int[] { i, j });
                }
                for (int k = 1; k < grid[i][j]; k++) {
                    list2.add(new int[] { i, j });
                }
            }
        }
        return minimumMoves(0, list1, list2);
    }

    private int minimumMoves(int index, ArrayList<int[]> list1, ArrayList<int[]> list2) {
        if (index == list1.size()) {
            return 0;
        }
        int min = Integer.MAX_VALUE, temp[] = list1.get(index);
        for (int i = index; i < list1.size(); i++) {
            list1.set(index, list1.get(i));
            list1.set(i, temp);
            min = Math.min(min, Math.abs(list1.get(index)[0] - list2.get(index)[0])
                    + Math.abs(list1.get(index)[1] - list2.get(index)[1]) + minimumMoves(index + 1, list1, list2));
            list1.set(i, list1.get(index));
            list1.set(index, temp);
        }
        return min;
    }


    public static void main(String[] args) throws InterruptedException {


        Thread t = new Thread(() -> {

            System.out.println(" execute ");
            throw new RuntimeException(" exeception ");

        }, "t");

        t.start();

        TimeUnit.SECONDS.sleep(4);

        System.out.println(" wake up!");

    }



}
